﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace HardwareAs
{
    public partial class Products : System.Web.UI.Page
    {
        SqlRequest sr = new SqlRequest();
     
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
               CategoryTitle.Items.Insert(0, "-Select the product-");
               ProductTitle.Items.Insert(0, "-Select The type-");
              
               
                    //SqlRequest sr = new SqlRequest();


                    Manu.DataTextField = "Title";
                    Manu.DataValueField = "Id";
                    Manu.DataSource = sr.AddFactory();
                    Manu.DataBind();
                
                 Manu.Items.Insert(0, "-Select the manufacture-");


            }

        }

        protected void Manu_SelectedIndexChanged(object sender, EventArgs e)
        {
           //SqlRequest sr = new SqlRequest();
           if (Manu.SelectedIndex != 0)
           {
               CategoryTitle.DataTextField = "Description";
               CategoryTitle.DataValueField = "Id";
               CategoryTitle.DataSource = sr.AddCategory(Manu.SelectedValue);
               CategoryTitle.DataBind();
           
            
         CategoryTitle.Items.Insert(0, "-Select the product-");}
            
        }

        protected void CategoryTitle_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((Manu.SelectedIndex != 0) && (CategoryTitle.SelectedIndex != 0))
            {
                //SqlRequest sr = new SqlRequest();

                ProductTitle.DataTextField = "Title";
                ProductTitle.DataValueField = "Id";
                ProductTitle.DataSource = sr.AddProducts(CategoryTitle.SelectedValue);
                ProductTitle.DataBind();


                ProductTitle.Items.Insert(0, "-Select The type-");
            }

        }



        protected void Search_Click(object sender, EventArgs e)
        {
           //SqlRequest sr = new SqlRequest();
           if ((Manu.SelectedIndex != 0) && (CategoryTitle.SelectedIndex != 0) && (ProductTitle.SelectedIndex != 0))
           {
               Tagline.Text = sr.SearchInfo(Manu.SelectedValue, CategoryTitle.SelectedValue, ProductTitle.SelectedValue);
              
               Label1.Text = "The " + Manu.SelectedItem.Text + " " + CategoryTitle.SelectedItem.Text + " " + ProductTitle.SelectedItem.Text;
               Readmore.Visible = true;
               
               Image.Visible = true;
               Image.ImageUrl = sr.AddImage(Manu.SelectedValue, CategoryTitle.SelectedValue, ProductTitle.SelectedValue);
              
           }

        }

        
            
      

        protected void Readmore_Click(object sender, EventArgs e)
        {

            Session["description"] = sr.getDescription(Manu.SelectedValue, CategoryTitle.SelectedValue, ProductTitle.SelectedValue);
            Session["title"] = Label1.Text;
            Session["subtitle"] = Tagline.Text;

            Session["image"] = Image.ImageUrl;
            // Response.Redirect("~/Description.aspx");
            //Server.Transfer("~/Description.aspx");
            Response.Write("<script>window.open('Description.aspx','_blank')</script>");
        }

     
      
 
    
    }
}